# PascalTriangle.rb
# July 4, 2007
#

def row(r)
  i=0
  s=""
  while i <= r
    s += n_over_k(r,i).to_s + " "
    i += 1
  end
  s
end

def n_over_k(n,k)
  fak(n)/(fak(k)*fak(n-k)) 
end


def fak(k)
  k==0? 1:k*fak(k-1)
end


def pascal(r)
  0.upto(r) {|r| puts row(r)}
end

pascal(5)

